package com.cskaoyan.market.aspect;

import com.cskaoyan.market.db.domain.MarketUser;
import com.cskaoyan.market.service.WxCouponService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class CouponProvideAspect {
    @Autowired
    WxCouponService wxCouponService;
    @Pointcut("@annotation(com.cskaoyan.market.annotation.CouponProvide)")
    public void pt(){}

    @AfterReturning(value = "pt()",returning = "result")
    public void couponProvide(Object result){
        if (result!=null){
            MarketUser user= (MarketUser) result;
            Integer data = wxCouponService.couponProvide(user.getId());
            if(data!=0){
                System.out.println("新人优惠券发放失败");
            }
            else {
                System.out.println("新人优惠券发放成功");
            }
        }
    }
}

